const Router = require("koa-router")
const Server = require('./server')
const Check = require('./check')
const { auth } = require('@/lib/auth')

/**
 * 路由对象
 * @type {Router}
 */
const router = new Router({
	prefix: '/logs'
})

// ============================  me  ===============================
/**
 * 提交前端流程日志
 */
router.post("/web-process-add", async (ctx, next) => {
		Check.webProcessAdd(ctx)
		const data = await Server.webProcessAdd(ctx)
		ctx.sendSuccess(data)
})

/**
 * 提交ajax日志
 */
router.post("/web-ajax-add", async (ctx, next) => {
	Check.webAjaxAdd(ctx)
	const data = await Server.webAjaxAdd(ctx)
	ctx.sendSuccess(data)
})

/**
 * 提交错误日志
 */
router.post("/web-error-add", async (ctx, next) => {
	Check.webErrorAdd(ctx)
	const data = await Server.webErrorAdd(ctx)
	ctx.sendSuccess(data)
})

/**
 * 前端流程日志
 */
router.get("/web-process-list", auth, async (ctx, next) => {
	Check.webProcessList(ctx)
	const data = await Server.webProcessList(ctx)
	ctx.sendSuccess(data)
})

/**
 * 前端ajax日志
 */
router.get("/web-ajax-list", auth, async (ctx, next) => {
	Check.webAjaxList(ctx)
	const data = await Server.webAjaxList(ctx)
	ctx.sendSuccess(data)
})

/**
 * 前端error日志
 */
router.get("/web-error-list", auth, async (ctx, next) => {
	Check.webErrorList(ctx)
	const data = await Server.webErrorList(ctx)
	ctx.sendSuccess(data)
})

/**
 * 后端流程日志
 */
router.get("/server-process-list", auth, async (ctx, next) => {
	Check.serverProcessList(ctx)
	const data = await Server.serverProcessList(ctx)
	ctx.sendSuccess(data)
})

/**
 * 后端error日志
 */
router.get("/server-error-list", auth, async (ctx, next) => {
	Check.serverErrorList(ctx)
	const data = await Server.serverErrorList(ctx)
	ctx.sendSuccess(data)
})

module.exports = router
